﻿using AspNetCoreWebApiRoute.Filter;
using AspNetCoreWebApiRoute.ModelBinder;

namespace AspNetCoreWebApiRoute
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //1、性能统计 action 执行性能
            //2、日志记录 记录action执行记录
            //3、统一结果输出

            //创建web主机建造者对象
            WebApplicationBuilder webApplication = WebApplication.CreateBuilder();
            webApplication.WebHost.UseKestrel();
            webApplication.Services.AddControllers(option =>
            {
                //option.ModelBinderProviders.Insert(0, new CookieBinderProvider());
                //option.Filters.Add<MyActionFilterxx>();
                //option.Filters.Add<MyActionFilterAttribute>();

                //option.Filters.Add<ResultFilter>();
            });
            //webApplication.Services.AddControllers(option => option.ModelBinderProviders.Insert(0,new CookieBinderProvider()));
            webApplication.Services.AddSwaggerGen();
            webApplication.Logging.AddConsole();
            //webApplication.Services.AddTransient<ResultFilter>();
            //webApplication.Services.AddSingleton<MyActionFilterxx>();
            //webApplication.Services.AddSingleton<MyActionFilterAttribute>();  //第二种过滤方法 使用依赖注入方法可以注入一些必要的组件
            //webApplication.Host.
            //创建web主机
            WebApplication application = webApplication.Build();
            application.UseSwagger();
            application.UseSwaggerUI();
            application.Use(async (context, next) =>
            {
                var path = context.Request.Path;
                await next();
            });
            application.MapControllers();
            application.Urls.Add("http://+:5009");
            //运行主机
            application.Run();
        }
    }
}
